package io.renren.modules.stm.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.stm.entity.SectionsEntity;
import io.renren.modules.stm.service.SectionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



/**
 * 分组
 *
 * @author jie.xiong
 * @email jaaaad@163.com
 * @date 2020-07-12 21:38:44
 */
@RestController
@RequestMapping("/stm/sections")
@Api(value = "分组接口",description = "分组接口")
public class SectionsController {
    @Autowired
    private SectionsService sectionsService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("stm:sections:list")
    @ApiOperation(value="查询分组信息", notes="根据参数查询分组信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sectionsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("stm:sections:info")
    @ApiOperation(value="查询分组信息", notes="根据id查询分组信息")
    public R info(@PathVariable("id") Integer id){
		SectionsEntity sections = sectionsService.getById(id);

        return R.ok().put("sections", sections);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("stm:sections:save")
    @ApiOperation(value="保存分组信息", notes="保存分组信息")
    public R save(@RequestBody SectionsEntity sections){
		sectionsService.save(sections);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("stm:sections:update")
    @ApiOperation(value="更新分组信息", notes="更新分组信息")
    public R update(@RequestBody SectionsEntity sections){
		sectionsService.updateById(sections);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("stm:sections:delete")
    @ApiOperation(value="删除分组信息", notes="根据id更新分组信息")
    public R delete(@RequestBody Integer[] ids){
		sectionsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
